package com.yf.controller.admin.article;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import com.yf.consts.DaoConst;
import com.yf.entity.ShareEntity;
import com.yf.response.R;
import com.yf.service.article.ShareService;
import com.yf.vo.ShareBackVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;



/**
 * 分享Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Tue Aug 21 11:02:52 CST 2018
 */
@RestController
@RequestMapping("/share")
public class ShareController {

    @Autowired
    private ShareService shareService;

    /**
     * 列表分享
     */
    @RequestMapping("/list")
    @RequiresPermissions("share:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<ShareEntity> shareList = shareService.queryList(params);
        return R.ok(new PageInfo(shareList));
    }

    /**
     * 查看分享
     */
    @SysLog("查看分享")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("share:info")
    public R info(@PathVariable("id") Long id) {
        ShareEntity share = shareService.get(id);

        return R.ok(share);
    }

    /**
     * 保存分享
     */
    @SysLog("保存分享")
    @RequestMapping("/save")
    @RequiresPermissions("share:save")
    public R save(ShareEntity share) {
        shareService.save(share);

        return R.ok(share);
    }

    /**
     * 修改分享
     */
    @SysLog("修改分享")
    @RequestMapping("/update")
    @RequiresPermissions("share:update")
    public R update(ShareEntity share) {
        shareService.update(share);

        return R.ok(share);
    }

    /**
     * 删除分享
     */
    @SysLog("删除分享")
    @RequestMapping("/delete")
    @RequiresPermissions("share:delete")
    public R delete(@RequestBody Long[]ids) {
        shareService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有分享
     */
    @SysLog("所有分享")
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<ShareEntity> shareList = shareService.queryList(params);

        return R.ok(shareList);
    }

    /***********自定义开始***********/

    /**
     * back 分享记录
     * @param params
     * @return
     */
    @RequestMapping("/shareRecord")
    public R findShareRecord(@RequestParam Map<String, Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<ShareBackVo> list = shareService.findShareRecord(params);
        return R.ok(new PageInfo(list));
    }

}
